<?php

namespace App\Http\Controllers;

use App\Models\Cart;
use D1M\Common\Helpers\Result;
use Illuminate\Http\Request;
use App\Http\Requests\CartRequest;
use Illuminate\Support\Facades\DB;

class CartController extends Controller
{
    public function store(CartRequest $request){
        $params = $request->input();

        try {
            $cartMdl = new Cart();
            $cartMdl->saveCart($params);
        }catch (\Exception $e){
            return Result::error($e->getMessage(),$e->getCode());
        }

        return Result::success();
    }

    public function edit(CartRequest $request){

        $params = $request->input();

        try {
            DB::beginTransaction();
            $cartMdl = new Cart();
            $cartMdl->editCart($params);
        }catch (\Exception $e){
            DB::rollBack();
            return Result::error($e->getMessage(),$e->getCode());
        }
        DB::commit();
        return Result::success();

    }

}
